package com.hksj.Intelligentmanagement.controller;

import com.hksj.Intelligentmanagement.common.Result;
import com.hksj.Intelligentmanagement.dto.GatewayDTO;
import com.hksj.Intelligentmanagement.service.GatewayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "网关管理")
@RequestMapping("/api/gateway")
public class GatewayController {

    @Autowired
    private GatewayService gatewayService;

    @ApiOperation("新增网关")
    @PostMapping("/createGateway")
    public Result createGateway(@RequestBody GatewayDTO gatewayDTO) {
        return gatewayService.createGateway(gatewayDTO);
    }

    @ApiOperation("删除网关")
    @DeleteMapping("/deleteGateway/{id}")
    public Result deleteGateway(@PathVariable("id") String id) {
        return gatewayService.deleteGateway(id);
    }

    @ApiOperation("修改网关")
    @PutMapping("/updateGateway")
    public Result updateGateway(@RequestBody GatewayDTO gatewayDTO) {
        return gatewayService.updateGateway(gatewayDTO);
    }

    @ApiOperation("通过sn号查询网关")
    @GetMapping("/queryGatewayBySNId/{snId}")
    public Result queryGatewayBySNId(@PathVariable("snId") String snId) {
        return gatewayService.queryGatewayBySNId(snId);
    }

    @ApiOperation("动态分页查询网关列表")
    @PostMapping("/queryGatewayListByPage")
    public Result queryGatewayListByPage(@RequestBody GatewayDTO gatewayDTO) {
        return Result.ok(gatewayService.queryGatewayListByPage(gatewayDTO));
    }

    @ApiOperation("新增网关和mqtt认证参数的拓扑关系")
    @PostMapping("/createGatewayAuthTopo")
    public Result createGatewayAuthTopo(@RequestBody GatewayDTO gatewayDTO) {
        return gatewayService.createGatewayAuthTopo(gatewayDTO);
    }

    @ApiOperation("删除网关和mqtt认证参数的拓扑关系")
    @DeleteMapping("/deleteGatewayAuthTopo")
    public Result deleteGatewayAuthTopo(@RequestBody GatewayDTO gatewayDTO) {
        return gatewayService.deleteGatewayAuthTopo(gatewayDTO);
    }

    @ApiOperation("新增网关和设备的拓扑关系")
    @PostMapping("/createGatewayDeviceTopo")
    public Result createGatewayDeviceTopo(@RequestBody GatewayDTO gatewayDTO) {
        return gatewayService.createGatewayDeviceTopo(gatewayDTO);
    }

    @ApiOperation("删除网关和设备的拓扑关系")
    @DeleteMapping("/deleteGatewayDeviceTopo")
    public Result deleteGatewayDeviceTopo(@RequestBody GatewayDTO gatewayDTO) {
        return gatewayService.deleteGatewayDeviceTopo(gatewayDTO);
    }

    @ApiOperation("通过网关id查询mqtt参数列表")
    @PostMapping("/queryMqttAuthListByGatewayId")
    public Result queryMqttAuthListByGatewayId(@RequestBody GatewayDTO gatewayDTO) {
        return Result.ok(gatewayService.queryMqttAuthListByGatewayId(gatewayDTO));
    }

    @ApiOperation("通过网关id查询设备列表")
    @PostMapping("/queryDeviceListByGatewayId")
    public Result queryDeviceListByGatewayId(@RequestBody GatewayDTO gatewayDTO) {
        return Result.ok(gatewayService.queryDeviceListByGatewayId(gatewayDTO));
    }

}
